import requests
import random
import json
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
import urllib3
import logging
from urllib3.exceptions import InsecureRequestWarning
import concurrent.futures
import openpyxl
headers={
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36',
    'Cookie':'sb=hi56YOpNDlQncEQ8PI6wp1V9; datr=hi56YIed78YGGIT_bDTI8fMI; locale=en_GB; wd=1920x881; c_user=100065307048109; xs=12%3AFWm2uOD1acV82Q%3A2%3A1619071513%3A-1%3A-1; fr=1bwrISh1KoZNWWNO6.AWWddbPlb8Sys-EaZeY3XQvS1X4.BggREL._Q.AAA.0.0.BggRIZ.AWVrd5O1BlQ; spin=r.1003664707_b.trunk_t.1619071514_s.1_v.2_',
    'referer': 'https://www.facebook.com/cvlifeoutdoors/settings/?tab=people_and_other_pages&cquick=jsc_c_27&cquick_token=AQ6DMTA7FYcdJNWEmD8&ctarget=https%3A%2F%2Fwww.facebook.com'
}
intt=int(random.random()*10000)
data={
'__user': '100065307048109',
'__a': '1',
'__dyn': '7xeUmBwjbgmwn8K2V4Wo5O12wAxu13wqovzEdEc8uw9-dwJx61Mwaa3y4o3BwbC0LVE4W0OE2WxO0FE662y1nzUO0n2US1kyE5Wcwaq2l2Utwwwi8188fo2IzUuw9O0RE5a1qw8W1uwa-0raazo',
'__csr':'',
'__req': f'{int(random.random()*10)}',
'__beoa': '0',
'__pc': 'PHASED:DEFAULT',
'__bhv': '2',
'dpr': '1',
'__ccg': 'EXCELLENT',
'__rev': f'100353{intt}',
'__s': 'hen92d:qht9bf:lk544v',
'__hsi': f'6945{int(random.random()*1000000000000000)}-0',
'__comet_req': '0',
'cquick': 'jsc_c_3i',
'cquick_token': 'AQ706-755g8wVb2pzUw',
'ctarget': 'https://www.facebook.com',
'fb_dtsg': 'AQEqz71v3d1u:AQGQeiZRupsA',
'jazoest': f'{int(random.random()*100000)}',
'__spin_r': f'100353{intt}',
'__spin_b': 'trunk',
'__spin_t': f'16170{int(random.random()*100000)}'
}

# 选择浏览器
browser = webdriver.Chrome()
# 访问facebook网页
browser.get('https://www.facebook.com/login.php?login_attempt=1&lwv=110/')
browser.maximize_window()
# 输入账户密码
browser.find_element_by_id('email').clear()
browser.find_element_by_id('email').send_keys('jim_clear@163.com')
browser.find_element_by_id('pass').clear()
browser.find_element_by_id('pass').send_keys('jimclear')
# 模拟点击登录按钮，两种不同的点击方法。。。
try:
    browser.find_element_by_xpath('//button[@id="loginbutton"]').send_keys(Keys.ENTER)
except:
    browser.find_element_by_xpath('//input[@tabindex="4"]').send_keys(Keys.ENTER)
    browser.find_element_by_xpath('//a[@href="https://www.facebook.com/?ref=logo"]').send_keys(Keys.ENTER)
result = EC.alert_is_present()(browser)  # 检测是否有弹窗
if result:  # 当有弹窗时
    al = browser.switch_to_alert()  # 获取弹窗的位置
    time.sleep(random.random() * 10)
    al.accept()
time.sleep(10)
browser.find_element_by_xpath("//ul/li[2]/div/a[@class='oajrlxb2 gs1a9yip g5ia77u1 mtkw9kbi tlpljxtp qensuy8j ppp5ayq2 goun2846 ccm00jje s44p3ltw mk2mc5f4 rt8b4zig n8ej3o3l agehan2d sk4xxmp2 rq0escxv nhd2j8a9 a8c37x1j mg4g778l btwxx1t3 pfnyh3mw p7hjln8o kvgmc6g5 cxmmr5t8 oygrvhab hcukyx3x tgvbjcpo hpfvmrgz jb3vyjys rz4wbd8a qt6c0cv9 a8nywdso l9j0dhe7 i1ao9s8h esuyzwwr f1sip0of du4w35lb lzcic4wl abiwlrkh p8dawk7l ue3kfks5 pw54ja7n uo3d90p7 l82x9zwi']/div[@class='ow4ym5g4 auili1gw rq0escxv j83agx80 buofh1pr g5gj957u i1fnvgqd oygrvhab cxmmr5t8 hcukyx3x kvgmc6g5 nnctdnn4 hpfvmrgz qt6c0cv9 jb3vyjys l9j0dhe7 du4w35lb bp9cbjyn btwxx1t3 dflh9lhu scb9dxdr']/div[@class='ow4ym5g4 auili1gw rq0escxv j83agx80 buofh1pr g5gj957u i1fnvgqd oygrvhab cxmmr5t8 hcukyx3x kvgmc6g5 tgvbjcpo hpfvmrgz qt6c0cv9 rz4wbd8a a8nywdso jb3vyjys du4w35lb bp9cbjyn btwxx1t3 l9j0dhe7']/div[@class='gs1a9yip ow4ym5g4 auili1gw rq0escxv j83agx80 cbu4d94t buofh1pr g5gj957u i1fnvgqd oygrvhab cxmmr5t8 hcukyx3x kvgmc6g5 tgvbjcpo hpfvmrgz rz4wbd8a a8nywdso l9j0dhe7 du4w35lb rj1gh0hx pybr56ya f10w8fjw']/div/div[@class='j83agx80 cbu4d94t ew0dbk1b irj2b8pg']/div[@class='qzhwtbm6 knvmm38d'][1]/span[@class='d2edcug0 hpfvmrgz qv66sw1b c1et5uql lr9zc1uh a8c37x1j keod5gw0 nxhoafnm aigsh9s9 d3f4x2em fe6kdd0r mau55g9w c8b282yb iv3no6db jq4qci2q a3bd9o3v ekzkrbhg oo9gr5id hzawbc8m']/span[@class='a8c37x1j ni8dbmo4 stjgntxs l9j0dhe7']").click()
time.sleep(random.random()*10+6)
browser.find_element_by_xpath("//div[@class='aov4n071']/div[@class='dhix69tm oygrvhab cxmmr5t8 kvgmc6g5']/div/a[@class='oajrlxb2 gs1a9yip g5ia77u1 mtkw9kbi tlpljxtp qensuy8j ppp5ayq2 goun2846 ccm00jje s44p3ltw mk2mc5f4 rt8b4zig n8ej3o3l agehan2d sk4xxmp2 rq0escxv nhd2j8a9 a8c37x1j mg4g778l btwxx1t3 pfnyh3mw p7hjln8o kvgmc6g5 cxmmr5t8 oygrvhab hcukyx3x tgvbjcpo hpfvmrgz jb3vyjys rz4wbd8a qt6c0cv9 a8nywdso l9j0dhe7 i1ao9s8h esuyzwwr f1sip0of du4w35lb lzcic4wl abiwlrkh p8dawk7l ue3kfks5 pw54ja7n uo3d90p7 l82x9zwi']/div[@class='ow4ym5g4 auili1gw rq0escxv j83agx80 buofh1pr g5gj957u i1fnvgqd oygrvhab cxmmr5t8 hcukyx3x kvgmc6g5 nnctdnn4 hpfvmrgz qt6c0cv9 jb3vyjys l9j0dhe7 du4w35lb bp9cbjyn btwxx1t3 dflh9lhu scb9dxdr']/div[@class='ow4ym5g4 auili1gw rq0escxv j83agx80 buofh1pr g5gj957u i1fnvgqd oygrvhab cxmmr5t8 hcukyx3x kvgmc6g5 tgvbjcpo hpfvmrgz qt6c0cv9 rz4wbd8a a8nywdso jb3vyjys du4w35lb bp9cbjyn btwxx1t3 l9j0dhe7']/div[@class='gs1a9yip ow4ym5g4 auili1gw rq0escxv j83agx80 cbu4d94t buofh1pr g5gj957u i1fnvgqd oygrvhab cxmmr5t8 hcukyx3x kvgmc6g5 tgvbjcpo hpfvmrgz rz4wbd8a a8nywdso l9j0dhe7 du4w35lb rj1gh0hx pybr56ya f10w8fjw']/div/div[@class='j83agx80 cbu4d94t ew0dbk1b irj2b8pg']/div[@class='qzhwtbm6 knvmm38d'][1]/span[@class='d2edcug0 hpfvmrgz qv66sw1b c1et5uql lr9zc1uh a8c37x1j keod5gw0 nxhoafnm aigsh9s9 d3f4x2em fe6kdd0r mau55g9w c8b282yb iv3no6db jq4qci2q a3bd9o3v ekzkrbhg oo9gr5id hzawbc8m']").click()
time.sleep(random.random()*10+6)
browser.find_element_by_xpath("//div[@class='q5bimw55 rpm2j7zs k7i0oixp gvuykj2m j83agx80 cbu4d94t ni8dbmo4 eg9m0zos l9j0dhe7 du4w35lb ofs802cu pohlnb88 dkue75c7 mb9wzai9 d8ncny3e buofh1pr g5gj957u tgvbjcpo l56l04vs r57mb794 kh7kg01d c3g1iek1 k4xni2cv']/div[@class='j83agx80 cbu4d94t buofh1pr l9j0dhe7']/div[@class='aov4n071']/div[@class='tr9rh885']/div[10]/a[@class='oajrlxb2 gs1a9yip g5ia77u1 mtkw9kbi tlpljxtp qensuy8j ppp5ayq2 goun2846 ccm00jje s44p3ltw mk2mc5f4 rt8b4zig n8ej3o3l agehan2d sk4xxmp2 rq0escxv nhd2j8a9 a8c37x1j mg4g778l btwxx1t3 pfnyh3mw p7hjln8o kvgmc6g5 cxmmr5t8 oygrvhab hcukyx3x tgvbjcpo hpfvmrgz jb3vyjys rz4wbd8a qt6c0cv9 a8nywdso l9j0dhe7 i1ao9s8h esuyzwwr f1sip0of du4w35lb lzcic4wl abiwlrkh p8dawk7l ue3kfks5 pw54ja7n uo3d90p7 l82x9zwi']/div[@class='ow4ym5g4 auili1gw rq0escxv j83agx80 buofh1pr g5gj957u i1fnvgqd oygrvhab cxmmr5t8 hcukyx3x kvgmc6g5 nnctdnn4 hpfvmrgz qt6c0cv9 jb3vyjys l9j0dhe7 du4w35lb bp9cbjyn btwxx1t3 dflh9lhu scb9dxdr']/div[@class='ow4ym5g4 auili1gw rq0escxv j83agx80 buofh1pr g5gj957u i1fnvgqd oygrvhab cxmmr5t8 hcukyx3x kvgmc6g5 tgvbjcpo hpfvmrgz qt6c0cv9 rz4wbd8a a8nywdso jb3vyjys du4w35lb bp9cbjyn btwxx1t3 l9j0dhe7']/div[@class='gs1a9yip ow4ym5g4 auili1gw rq0escxv j83agx80 cbu4d94t buofh1pr g5gj957u i1fnvgqd oygrvhab cxmmr5t8 hcukyx3x kvgmc6g5 tgvbjcpo hpfvmrgz rz4wbd8a a8nywdso l9j0dhe7 du4w35lb rj1gh0hx pybr56ya f10w8fjw']/div/div[@class='j83agx80 cbu4d94t ew0dbk1b irj2b8pg']/div[@class='qzhwtbm6 knvmm38d']/span[@class='d2edcug0 hpfvmrgz qv66sw1b c1et5uql lr9zc1uh a8c37x1j keod5gw0 nxhoafnm aigsh9s9 d3f4x2em fe6kdd0r mau55g9w c8b282yb mdeji52x a5q79mjw g1cxx5fr ekzkrbhg oo9gr5id hzawbc8m']").click()
time.sleep(random.random()*10+6)
browser.find_element_by_xpath("//div[@class='aov4n071']/div[@class='r54jmrld']/div[6]/a[@class='oajrlxb2 gs1a9yip g5ia77u1 mtkw9kbi tlpljxtp qensuy8j ppp5ayq2 goun2846 ccm00jje s44p3ltw mk2mc5f4 rt8b4zig n8ej3o3l agehan2d sk4xxmp2 rq0escxv nhd2j8a9 a8c37x1j mg4g778l btwxx1t3 pfnyh3mw p7hjln8o kvgmc6g5 cxmmr5t8 oygrvhab hcukyx3x tgvbjcpo hpfvmrgz jb3vyjys rz4wbd8a qt6c0cv9 a8nywdso l9j0dhe7 i1ao9s8h esuyzwwr f1sip0of du4w35lb lzcic4wl abiwlrkh p8dawk7l ue3kfks5 pw54ja7n uo3d90p7 l82x9zwi']/div[@class='ow4ym5g4 auili1gw rq0escxv j83agx80 buofh1pr g5gj957u i1fnvgqd oygrvhab cxmmr5t8 hcukyx3x kvgmc6g5 nnctdnn4 hpfvmrgz qt6c0cv9 jb3vyjys l9j0dhe7 du4w35lb bp9cbjyn btwxx1t3 dflh9lhu scb9dxdr']/div[@class='ow4ym5g4 auili1gw rq0escxv j83agx80 buofh1pr g5gj957u i1fnvgqd oygrvhab cxmmr5t8 hcukyx3x kvgmc6g5 tgvbjcpo hpfvmrgz qt6c0cv9 rz4wbd8a a8nywdso jb3vyjys du4w35lb bp9cbjyn btwxx1t3 l9j0dhe7']/div[@class='gs1a9yip ow4ym5g4 auili1gw rq0escxv j83agx80 cbu4d94t buofh1pr g5gj957u i1fnvgqd oygrvhab cxmmr5t8 hcukyx3x kvgmc6g5 tgvbjcpo hpfvmrgz rz4wbd8a a8nywdso l9j0dhe7 du4w35lb rj1gh0hx pybr56ya f10w8fjw']/div/div[@class='j83agx80 cbu4d94t ew0dbk1b irj2b8pg']/div[@class='qzhwtbm6 knvmm38d']/span[@class='d2edcug0 hpfvmrgz qv66sw1b c1et5uql lr9zc1uh a8c37x1j keod5gw0 nxhoafnm aigsh9s9 d3f4x2em fe6kdd0r mau55g9w c8b282yb mdeji52x a5q79mjw g1cxx5fr ekzkrbhg oo9gr5id hzawbc8m']").click()
time.sleep(random.random()*10+6)




n = 2000
m = 0
while m < 1500:
    browser.execute_script(f"window.scrollTo(0,{n})")
    m += 10
    print(m, '*************************************', n)

    time.sleep(3)











